package com.campusnews.controller;


import com.campusnews.pojo.Build;
import com.campusnews.pojo.Location;
import com.campusnews.pojo.dayData;
import com.campusnews.service.*;
import com.campusnews.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javafx.concurrent.ScheduledService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lqc
 * @since 2021-10-14
 */
@RestController
@RequestMapping("/dataVisual")
@Api(tags={"数据可视化API"})
public class DataVisualController {

    @Autowired
    private DataVisualService dataVisualService;

    @Autowired
    private BuildService buildService;

    //    @LoginToken
    @ApiOperation(value = "最近七天的帖子发布数量", notes = "最近七天的帖子发布数量")
    @RequestMapping(value = "/sevenDayInviteNum" ,method = RequestMethod.GET)
    public JsonResult sevenDayInviteNum() {
        List<dayData> num = dataVisualService.getSevenDayInviteNum();
        return JsonResult.build(200,"最近七天的帖子发布数量",num);
    }


    //    @LoginToken
    @ApiOperation(value = "最近七天的用户新增数量", notes = "最近七天的用户新增数量")
    @RequestMapping(value = "/SevenDayUserNum" ,method = RequestMethod.GET)
    public JsonResult SevenDayUserNum() {
        List<dayData> num = dataVisualService.getSevenDayUserNum();
        return JsonResult.build(200,"最近七天的用户新增数量",num);
    }


    //    @LoginToken
    @ApiOperation(value = "最近七天的话题发布数量", notes = "最近七天的话题发布数量")
    @RequestMapping(value = "/SevenDayTopicNum" ,method = RequestMethod.GET)
    public JsonResult SevenDayTopicNum() {
        List<dayData> num = dataVisualService.getSevenDayTopicNum();
        return JsonResult.build(200,"最近七天的话题发布数量",num);
    }

    //    @LoginToken
    @ApiOperation(value = "地点帖子数量", notes = "地点帖子数量")
    @RequestMapping(value = "/BuildInviteNum" ,method = RequestMethod.GET)
    public JsonResult selectBuildByAccurate() {
        List<Build> list = buildService.list();
        ArrayList<Location> locations = new ArrayList<>();
        for (Build build : list) {
            Location location = new Location(build.getBuildName(),build.getInviNum());
            locations.add(location);
        }
        return JsonResult.build(200,"分页精确地点信息查询成功",locations);
    }


    //    @LoginToken
    @ApiOperation(value = "其他总数数量", notes = "其他总数数量")
    @RequestMapping(value = "/otherTotalNum" ,method = RequestMethod.GET)
    public JsonResult otherTotalNum() {
        Map<String, Integer> map = dataVisualService.countTotalNum();
        return JsonResult.build(200,"其他总数数量",map);
    }
}
